import React, { Component } from 'react';
import '../components/Allsearch.scss'

class Allsearch extends Component {
    constructor(props) {
        super(props);
        this.state = {
            searchKey: ""
        }
    }
    handleEnter(e) {
        this.setState({
            [e.target.name]: e.target.value
        })
    }
    redirectPage() {
        this.props.history.push({ pathname: '/index/allgoods', state: { searchKey: this.state.searchKey } })
    }
    render() {
        return (
            <div className='allsearch' >
                <input type="text" className='iconfont' placeholder='&#xe651; 请输入你想搜的产品'
                    name="searchKey"
                    value={this.state.searchKey}
                    onChange={(e) => {
                        this.handleEnter(e)
                    }}
                    onKeyUp={(e) => {
                        if (e.keyCode == 13) {
                            this.redirectPage()
                        }
                    }}
                />
            </div>
        );
    }
}

export default Allsearch;